/**
 * login.js
 *
 * @author LongShu 2017/06/05
 */
(function () {
    var login_form = new Vue({
        el: '#login_form',
        data: {
            userModel: {
                username: '',
                password: ''
            }
        },
        methods: {
            login: function () {
                this.$http.post(fixUrl('user/login'), this.userModel, {
                    emulateJSON: true
                }).then(function (response) {
                    var webData = new WebData(response.body);
                    if (webData.isError()) {
                        alert(webData.msg);
                        return false;
                    }
                    alert(webData.data.name + webData.msg);
                    if (webData.isMsg()) {
                        Cookies.set('username', login_form.userModel.username, {expires: 7, path: '/'});
                        toLocation('user/myInfo');// 用户信息
                    }
                }, function (response) {
                    console.warn(response.body);
                    alert("系统错误,登录失败!");
                });
            }
        }// methods
    });

    var username = Cookies.get("username");
    if (username) {
        login_form.userModel.username = username;
    }
})();
